from libs.appium_driver import driver
from libs.ocr import findString
from libs.utils import text_to_speech
import pytz
from datetime import datetime   
import time
china_tz = pytz.timezone('Asia/Shanghai')
success = 0
fail = 0
needReplace = False
limitTime = 4000
def moveRole(time = 1):
    x1 = 167
    x2 = 472
    y1 = 832
    y2 = 380
    driver.swipe(x1,y1,x1,y2,duration=2)
    if time == 2:
        driver.swipe(x1,y1,x2,y2,duration=2)

while True:
    strList = ['重试','以后再说','继续','闪电特卖','梅迪希高塔','好的','跳过','中心城区','木板路','15号','枫叶','大教堂','反骷髅','河王赌场']
    if needReplace:
        strList.append('团队')
        strList.append('退出')
    else:
        strList.insert(0,'重赛')
        strList.append('开始对决')
    _,_,_,res = findString(strList,tap=True,loop=True,like=True)
    if res == '继续':
        success += 1
        if success >= limitTime:
            needReplace = True
    if res == '重赛':
        fail += 1
        print('success',success,'fail',fail-success,"北京时间:", datetime.now(china_tz).strftime('%Y-%m-%d %H:%M:%S'))
        # time.sleep(24)
    if '闪电特卖' in res:
        driver.tap(1658,141)
    if '梅迪希高塔' in res:
        driver.tap(1503,531)
    if '中心城区' in res:
        driver.tap(877,524)
    if '木板路' in res:
        driver.tap(794,546)
    if '15号' in res:
        driver.tap(1693,561)
    if '大教堂' in res:
        driver.tap(1713,529)
    if '枫叶' in res:
        driver.tap(975,550)
    if '反骷髅' in res:
        driver.tap(1030,771)
    if '河王赌场' in res:
        driver.tap(970,550)
    if '以后再说' in res:
        needReplace = True
    if '团队' in res:
        moveRole(2)
        success = 0
        fail = 0
        needReplace = False
            
